﻿<?php
	
	function listaDir($local) {
		$arquivos = array();
		if (!$local) { return false; }
		if (!is_dir($local)) { 
			array_push($arquivos, $local);
		} else {
			$dir = opendir($local);
			while ($file = readdir($dir)) {
		 	if ($file != "." && $file != ".." && $file != "gerarZip.php") {
				$ls = listaDir(($local . "/" . $file));
				foreach($ls as $fl){
					array_push($arquivos, $fl);
				}
				unset($file);
			}
		}
		closedir($dir);
		unset($dir);
		}
		return $arquivos;
	}
	if(is_file("./tgvos.zip")){
		unlink("./tgvos.zip");
	}
	$lista = listaDir('.');
	$zip = new ZipArchive();
	$filename = "./tgvos.zip";
	if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
    	exit("cannot open <$filename>\n");
	}
	foreach($lista as $ls){
		$zip->addFile($ls,$ls);
	}
	$zip->close();	
	header ("location: tgvos.zip");	
?>